package com.youku.plugins.logo.view
{
   import flash.display.MovieClip;
   import com.youku.interfaces.IPlayerProxy;
   import com.youku.events.PlayerControlEvent;
   import com.youku.events.ConductorEvent;
   import com.youku.events.CoreEvent;
   import com.youku.conductor.ConductorState;
   
   public class LogoMediator extends Object
   {
      
      public function LogoMediator(param1:MovieClip, param2:IPlayerProxy) {
         super();
         this._mainMc = param1;
         this._playerProxy = param2;
         this.init();
      }
      
      private var _mainMc:MovieClip;
      
      private var _playerProxy:IPlayerProxy;
      
      private var _logo:Logo;
      
      private function init() : void {
         this._logo = new Logo();
         this._mainMc.addChild(this._logo);
         this.addEvents();
      }
      
      private function addEvents() : void {
         this._playerProxy.addEventListener(PlayerControlEvent.FULLSCREEN_CHANGED,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(PlayerControlEvent.PLAYER_SIZE_CHANGED,this.onPlayerControlEvent);
         this._playerProxy.addEventListener(ConductorEvent.STATE_CHANGED,this.onStateChanged);
         this._playerProxy.addEventListener(CoreEvent.QUALITY_CHANGED,this.onCoreEvent);
      }
      
      private function onPlayerControlEvent(param1:PlayerControlEvent) : void {
         var _loc2_:* = NaN;
         var _loc3_:* = NaN;
         var _loc4_:* = false;
         var _loc5_:* = NaN;
         switch(param1.type)
         {
            case PlayerControlEvent.PLAYER_SIZE_CHANGED:
            case PlayerControlEvent.FULLSCREEN_CHANGED:
               _loc2_ = param1.data.width;
               _loc3_ = param1.data.height;
               _loc4_ = param1.data.fullscreen;
               _loc5_ = param1.data.cheight;
               if(_loc4_)
               {
                  this._logo.setSize(_loc2_,_loc3_);
               }
               else
               {
                  this._logo.setSize(_loc2_,_loc3_ - _loc5_);
               }
               break;
         }
      }
      
      private function onCoreEvent(param1:CoreEvent) : void {
         switch(param1.type)
         {
            case CoreEvent.QUALITY_CHANGED:
               this.show();
               break;
         }
      }
      
      private function onStateChanged(param1:ConductorEvent) : void {
         var _loc2_:String = param1.data as String;
         switch(_loc2_)
         {
            case ConductorState.VIDEO:
               this.hide();
               this.show();
               break;
            case ConductorState.INITIALIZE:
            case ConductorState.PRE_VIDEO:
            case ConductorState.POST_VIDEO:
            case ConductorState.VIDEO_END:
            case ConductorState.ERROR:
               this.hide();
               break;
            case ConductorState.AD:
               this.hide();
               break;
         }
      }
      
      private function show() : void {
         this.tryShowYoukuWatermark();
      }
      
      private function hide() : void {
         this.hideYoukuWatermark();
      }
      
      private function tryShowYoukuWatermark() : void {
         if(this._playerProxy.partnerData)
         {
            if(this._playerProxy.partnerData.nobandData.status == 1)
            {
               this._logo.hide();
               return;
            }
         }
         if(this._playerProxy.playerData.watermark == false)
         {
            this._logo.show();
         }
         else
         {
            this._logo.hide();
         }
      }
      
      private function hideYoukuWatermark() : void {
         this._logo.hide();
      }
   }
}
